﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Frogism.Domain;

namespace Frogism.Web.Views.Book
{
    public partial class BookStatus : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              Core.IBookManager manager = ManagerService.GetBookManager();
                BookStats bookStats = new BookStats(manager.GetAll());

                int yearSoFar = bookStats.YearRead;
                double goalSoFar = bookStats.Goal;

                this.YearRead.Text = yearSoFar.ToString();
                this.Goal.Text = goalSoFar.ToString();
                this.Diff.Text = bookStats.Diff.ToString();
                this.Today.Text = bookStats.ReadToday.ToString();
                this.AverageRate.Text = bookStats.YearDailyAverage.ToString();
                double days = bookStats.DaysAhead;
                this.daysAhead.Text = days.ToString();
                if (days < 0) {
                  this.daysAhead.Style.Add("color", "red");
                }

                GoalRate.Text = bookStats.GoalRate.ToString();

                WeeksProgress.DataSource = bookStats.GetWeekDetails();
                WeeksProgress.DataBind();

            }

        }
    }
}